import csv
from flask_cors import CORS
from flask import Flask, request

server = Flask('app')
CORS(server, supports_credentials=True)
data_path = 'data.csv'


@server.route('/api/intro')
def get_info():
    user_id = request.args.get('id')
    data = csv.reader(open(data_path, 'r', encoding='utf-8'))
    for item in data:
        if item[0] == user_id:
            return {
                "name": item[1],
                "sex": item[2],
                "intro": item[3],
                "about": item[4]
        }
    return {
    "name": None,
    "sex": None,
    "intro": None,
    "about": None
  }


server.run('127.0.0.1', port=8080)
